//
//  AFHttpTool.m
//  RCloud_liv_demo
//
//  Created by Liv on 14-10-22.
//  Copyright (c) 2014年 RongCloud. All rights reserved.
//


#import "AFHttpTool.h"
#import "AFNetworking.h"
#import "Reachability.h"

//#define ContentType @"text/plain"
#define ContentType @"text/html"

@implementation AFHttpTool

+ (void)requestWihtMethod:(RequestMethodType)methodType
                      url:(NSString*)url
                   params:(NSDictionary*)params
                  success:(void (^)(id response))success
                  failure:(void (^)(NSError* err))failure
{
    //    NSURL* baseURL = [NSURL URLWithString:UrlMain];
    //获得请求管理者
    AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
    
    
//    AFHTTPRequestOperationManager* mgr = [[AFHTTPRequestOperationManager alloc] init];
//#ifdef ContentType
//    mgr.responseSerializer.acceptableContentTypes = [NSSet setWithObject:ContentType];
//#endif
//    mgr.requestSerializer.HTTPShouldHandleCookies = YES;
//    [mgr.requestSerializer setTimeoutInterval:20];
    
    WaittingMBProgressHUD(kKeyWindow, @"正在处理");
    NSArray *arrayKeys = [params allKeys];
    
    NSString *strParams = [NSString stringWithFormat:@"\n-------------start\nurl:%@",url];
    for (NSString *strkey in arrayKeys)
    {
        NSString *str = [NSString stringWithFormat:@"\nkey:%@\nvalue:%@",strkey,[params objectForKey:strkey]];
        strParams = [strParams stringByAppendingString:str];
    }
    NSString *str = [NSString stringWithFormat:@"\n--------------end"];
    strParams = [strParams stringByAppendingString:str];
    DebugLog(@"%@",strParams);
    
    url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    switch (methodType) {
        case RequestMethodTypeGet:
        {
            //GET请求
            
            
            
            [mgr GET:url parameters:params progress:^(NSProgress * _Nonnull downloadProgress) {
            } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                
                if (success) {
                    success(responseObject);
                }
                
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                
                if (failure) {
                    failure(error);
                }
                
                Reachability *reach = [Reachability reachabilityForInternetConnection];
                if (reach.isReachable)
                {
                    AlertWithTitleAndMessageAndDelegateAndCancelTitleAndOtherTitles(@"提示", @"网络不给力啊", self, @"确定", nil);
                }
                else
                {
                    AlertWithTitleAndMessageAndDelegateAndCancelTitleAndOtherTitles(@"提示", @"无网络连接，请检查网络", self, @"确定", nil);
                }
                
            }];
            
//            [mgr GET:url parameters:params
//             success:^(AFHTTPRequestOperation* operation, NSDictionary* responseObj) {
//                 FinishMBProgressHUD(kKeyWindow);
//                 if (![params[@"operAtt"] isEqualToString:@"downloadFile"])
//                 {
//                     DebugLog(@"\nresponseObj:\n%@",responseObj);
//                 }
//                 if (success) {
//                     success(responseObj);
//                 }
//             } failure:^(AFHTTPRequestOperation* operation, NSError* error) {
//                 DebugLog(@"\nerr:\n%@",error);
//                 if (failure) {
//                     failure(error);
//                 }
//                 
//                 Reachability *reach = [Reachability reachabilityForInternetConnection];
//                 if (reach.isReachable)
//                 {
//                     AlertWithTitleAndMessageAndDelegateAndCancelTitleAndOtherTitles(@"提示", @"网络不给力啊", self, @"确定", nil);
//                 }
//                 else
//                 {
//                     AlertWithTitleAndMessageAndDelegateAndCancelTitleAndOtherTitles(@"提示", @"无网络连接，请检查网络", self, @"确定", nil);
//                 }
//                 
//             }];
            
        }
            break;
        case RequestMethodTypePost:
        {
            //POST请求
            [mgr POST:url parameters:params
              success:^(AFHTTPRequestOperation* operation, NSDictionary* responseObj) {
                  FinishMBProgressHUD(kKeyWindow);
                  if (![params[@"operAtt"] isEqualToString:@"downloadFile"])
                  {
                      DebugLog(@"\nresponseObj:\n%@",responseObj);
                  }
                  if (success) {
                      success(responseObj);
                  }
              } failure:^(AFHTTPRequestOperation* operation, NSError* error) {
                  DebugLog(@"\nerr:\n%@",error);
                  if (failure) {
                      failure(error);
                  }
                  
                  Reachability *reach = [Reachability reachabilityForInternetConnection];
                  if (reach.isReachable)
                  {
                      AlertWithTitleAndMessageAndDelegateAndCancelTitleAndOtherTitles(@"提示", @"网络不给力啊", self, @"确定", nil);
                  }
                  else
                  {
                      AlertWithTitleAndMessageAndDelegateAndCancelTitleAndOtherTitles(@"提示", @"无网络连接，请检查网络", self, @"确定", nil);
                  }
                  
              }];
        }
            break;
        default:
            break;
    }
}

/*
 *上传文件
 */
+(void) FileServletWithTaskId:(NSString *) taskId
                     Position:(NSString *) position
                        Image:(UIImage*)image
                         Type:(NSString *)type
                         Time:(NSString *)time
                      success:(void (^)(id response))success
                      failure:(void (^)(NSError* err))failure
{
    
    
    NSString *strUrl = [NSString stringWithFormat:@"%@/FileServlet?taskId=%@&userId=%@&position=%@&type=%@&time=%@",UrlMainIP,taskId,ROOTDATASOURCE.UserId,[[position stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],type,[[time stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    DebugLog(@"UpLoadUrl:%@",strUrl);
    
    
    WaittingMBProgressHUD(kKeyWindow, @"正在处理");
    AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] init];
    [manager POST:strUrl parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        
        NSData *imageData = UIImageJPEGRepresentation(image, 0.5);
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        formatter.dateFormat = @"yyyyMMddHHmmss";
        NSString *str = [formatter stringFromDate:[NSDate date]];
        NSString *fileName = [NSString stringWithFormat:@"%@.jpg", str];
        
        [formData appendPartWithFileData:imageData name:@"myfiles" fileName:fileName mimeType:@"image/jpeg"];
        
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (success)
        {
            success(responseObject);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        
        DebugLog(@"\nerr:\n%@",error);
        if (failure) {
            failure(error);
        }
        
        Reachability *reach = [Reachability reachabilityForInternetConnection];
        if (reach.isReachable)
        {
            AlertWithTitleAndMessageAndDelegateAndCancelTitleAndOtherTitles(@"提示", @"网络不给力啊", self, @"确定", nil);
        }
        else
        {
            AlertWithTitleAndMessageAndDelegateAndCancelTitleAndOtherTitles(@"提示", @"无网络连接，请检查网络", self, @"确定", nil);
        }
    }];
}



/*
 *登录
 */
+(void) loginWithLoginName:(NSString *) loginName
             LoginPassword:(NSString *) loginPassword
                  DeviceNo:(NSString *) deviceNo
                   success:(void (^)(id response))success
                   failure:(void (^)(NSError* err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"LoginName\":\"%@\",\"LoginPassword\":\"%@\",\"DeviceNo\":\"%@\"}", loginName,EncryptPassword(loginPassword),deviceNo];
    NSDictionary *params = @{@"operAtt":@"login",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}
/*
 *工作提醒
 */
+(void)queryMessagesWithRows:(NSString *)rows
                       Order:(NSString *)order
               MessageStatus:(NSString *)messageStatus
                     StartId:(NSString *)startId
                     success:(void (^)(id response))success
                     failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"Rows\":\"%@\",\"Order\":\"%@\",\"MessageStatus\":\"%@\",\"UserId\":\"%@\",\"StartId\":\"%@\"}", rows,order,messageStatus,ROOTDATASOURCE.UserId,startId];
    NSDictionary *params = @{@"operAtt":@"queryMessages",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}

/*
 *工作提醒更新状态
 */
+(void)updateMessageWithMessageId:(NSString *)messageId
                          success:(void (^)(id response))success
                          failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"MessageId\":\"%@\",\"UserId\":\"%@\"}", messageId,ROOTDATASOURCE.UserId];
    NSDictionary *params = @{@"operAtt":@"updateMessage",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}

/*
 *查看存量项目
 */
+(void)getProjectStockWithPage:(NSString *)page
                       success:(void (^)(id response))success
                       failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"UserId\":\"%@\",\"page\":\"%@\"}",ROOTDATASOURCE.UserId,page];
    NSDictionary *params = @{@"operAtt":@"projectStock",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}

/*
 *查看在审项目
 */
+(void)getProjectJudgeWithPage:(NSString *)page
                  ProjectStage:(NSString *)projectStage
                       success:(void (^)(id response))success
                       failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"UserId\":\"%@\",\"projectStage\":\"%@\",\"page\":\"%@\"}",ROOTDATASOURCE.UserId,projectStage,page];
    NSDictionary *params = @{@"operAtt":@"projectJudge",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}


/*
 *根据flowTypeId获取待办业务列表
 */
+(void)getTaskListWithFlowTypeId:(NSString *)flowTypeId
                         success:(void (^)(id response))success
                         failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"flowTypeId\":\"%@\",\"UserId\":\"%@\"}", flowTypeId,ROOTDATASOURCE.UserId];
    NSDictionary *params = @{@"operAtt":@"getTaskList",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}

/*
 *获取待办业务列表单个详情
 */
+(void)getTaskDeatilWithFlowTypeId:(NSString *)flowTypeId
                            TaskId:(NSString *)taskId
                        WorkItemId:(NSString *)workItemId
                           success:(void (^)(id response))success
                           failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"flowTypeId\":\"%@\",\"TaskId\":\"%@\",\"WorkItemId\":\"%@\",\"UserId\":\"%@\"}", flowTypeId,taskId,workItemId,ROOTDATASOURCE.UserId];
    NSDictionary *params = @{@"operAtt":@"getTaskDeatil",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}

/*
 *根据flowTypeId获取经手业务列表
 */
+(void)getPassTaskWithPage:(NSString *)page
                  flowType:(NSString *)flowType
                   success:(void (^)(id response))success
                   failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"userId\":\"%@\",\"rows\":\"%@\",\"page\":\"%@\",\"flowType\":\"%@\"}",ROOTDATASOURCE.UserId,@"20",page,flowType];
    NSDictionary *params = @{@"operAtt":@"getPassTask",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}

/*
 *获取经手业务列表单个详情
 */
+(void)passTaskDetailWithProInstId:(NSString *)proInstId
                          PassType:(NSString *)passType
                           success:(void (^)(id response))success
                           failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"proInstId\":\"%@\",\"passType\":\"%@\",\"userId\":\"%@\"}", proInstId,passType,ROOTDATASOURCE.UserId];
    NSDictionary *params = @{@"operAtt":@"passTaskDetail",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}

/*
 *提交/批准/否决按钮
 */
+(void)flowSubmitWithFlowContextId:(NSString *)flowContextId
                  OptFlowContextId:(NSString *)optFlowContextId
                      TargetUserId:(NSString *)targetUserId
                     TargetUserId1:(NSString *)targetUserId1
                      WorkItemName:(NSString *)workItemName
                             ToAdd:(NSString *)toAdd
                           success:(void (^)(id response))success
                           failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"FlowContextId\":\"%@\",\"optFlowContextId\":\"%@\",\"TargetUserId\":\"%@\",\"TargetUserId1\":\"%@\",\"UserId\":\"%@\",\"WorkItemName\":\"%@\",\"toAdd\":\"%@\"}", flowContextId,optFlowContextId,targetUserId,targetUserId1,ROOTDATASOURCE.UserId,[[workItemName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],toAdd];
    NSDictionary *params = @{@"operAtt":@"flowSubmit",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}

+(void)flowSubmitWithFlowContextId:(NSString *)flowContextId
                  OptFlowContextId:(NSString *)optFlowContextId
                      TargetUserId:(NSString *)targetUserId
                      WorkItemName:(NSString *)workItemName
                             ToAdd:(NSString *)toAdd
                           success:(void (^)(id response))success
                           failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"FlowContextId\":\"%@\",\"optFlowContextId\":\"%@\",\"TargetUserId\":\"%@\",\"UserId\":\"%@\",\"WorkItemName\":\"%@\",\"toAdd\":\"%@\"}", flowContextId,optFlowContextId,targetUserId,ROOTDATASOURCE.UserId,[[workItemName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],toAdd];
    NSDictionary *params = @{@"operAtt":@"flowSubmit",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}

/*
 *退回到业务部按钮
 */
+(void)flowBackManagerWithFlowContextId:(NSString *)flowContextId
                       OptFlowContextId:(NSString *)optFlowContextId
                                success:(void (^)(id response))success
                                failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"FlowContextId\":\"%@\",\"optFlowContextId\":\"%@\",\"UserId\":\"%@\"}", flowContextId,optFlowContextId,ROOTDATASOURCE.UserId];
    NSDictionary *params = @{@"operAtt":@"flowBackManager",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}

/*
 *退回按钮
 */
+(void)flowBackWithFlowContextId:(NSString *)flowContextId
                OptFlowContextId:(NSString *)optFlowContextId
             TargetFlowContextId:(NSString *)targetFlowContextId
                    TargetUserId:(NSString *)targetUserId
                        BackType:(NSString *)backType
                     BackOpinion:(NSString *)backOpinion
                         success:(void (^)(id response))success
                         failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"FlowContextId\":\"%@\",\"targetFlowContextId\":\"%@\",\"optFlowContextId\":\"%@\",\"TargetUserId\":\"%@\",\"backType\":\"%@\",\"backOpinion\":\"%@\",\"UserId\":\"%@\"}", flowContextId,targetFlowContextId,optFlowContextId,targetUserId,backType,[[backOpinion stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],ROOTDATASOURCE.UserId];
    NSDictionary *params = @{@"operAtt":@"flowBack",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}

/*
 *通过appContextId和flowContextId获取详情
 */
+(void)getInfoWithAppContextId:(NSString *)appContextId
                 FlowContextId:(NSString *)flowContextId
                       success:(void (^)(id response))success
                       failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"FlowContextId\":\"%@\",\"UserId\":\"%@\"}", flowContextId,ROOTDATASOURCE.UserId];
    NSDictionary *params = @{@"operAtt":appContextId,@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}
/*
 *会议纪要
 */
+(void)getInfoWithAppContextIdT:(NSString *)appContextId
                        TasskId:(NSString *)taskId
                        success:(void (^)(id response))success
                        failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"taskId\":\"%@\",\"userId\":\"%@\"}", taskId,ROOTDATASOURCE.UserId];
    NSDictionary *params = @{@"operAtt":appContextId,@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}
/*
 *条件汇总
 */
+(void)getconditionCollectWithAppContextIdT:(NSString *)appContextId
                                    TasskId:(NSString *)taskId
                              FlowContextId:(NSString*)flowContextId
                                    success:(void (^)(id response))success
                                    failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"taskId\":\"%@\",\"userId\":\"%@\",\"flowContextId\":\"%@\"}", taskId,ROOTDATASOURCE.UserId,flowContextId];
    NSDictionary *params = @{@"operAtt":appContextId,@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}


/*
 *通过flowTypeId获取详情
 */
+(void)getInfoWithFlowTypeId:(NSString *)flowTypeId
                     success:(void (^)(id response))success
                     failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"UserId\":\"%@\"}",ROOTDATASOURCE.UserId];
    NSDictionary *params = @{@"operAtt":flowTypeId,@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}

/*
 *保存岗位意见
 */
+(void)saveOpinionWithFlowContextId:(NSString *)flowContextId
                            Opinion:(NSString *)opinion
                              State:(NSString *)state
               isTallyWithComTactic:(NSString *)isTallyWithComTactic
                            explain:(NSString *)explain
                        projectflow:(NSString *)projectflow
                   prjPrimaryScheme:(NSString *)prjPrimaryScheme
                      schemeExplain:(NSString *)schemeExplain
                            success:(void (^)(id response))success
                            failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"State\":\"%@\",\"FlowContextId\":\"%@\",\"UserId\":\"%@\",\"Opinion\":\"%@\",\"isTallyWithComTactic\":\"%@\",\"explain\":\"%@\",\"projectflow\":\"%@\",\"prjPrimaryScheme\":\"%@\",\"schemeExplain\":\"%@\"}", state,flowContextId,ROOTDATASOURCE.UserId,opinion,isTallyWithComTactic,explain,projectflow,prjPrimaryScheme,schemeExplain];
    NSDictionary *params = @{@"operAtt":@"saveOpinion",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}

/*
 *业务单元附件查询
 */
+(void)getDownLoadListWithFlowContextId:(NSString *)flowContextId
                                 TaskId:(NSString *)taskId
                                success:(void (^)(id response))success
                                failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"userId\":\"%@\",\"flowContextId\":\"%@\",\"taskId\":\"%@\",\"type\":\"flow\"}", ROOTDATASOURCE.UserId,flowContextId,taskId];
    NSDictionary *params = @{@"operAtt":@"downLoadList",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}

/*
 *放款面签附件查询
 */
+(void)getDownLoadListWithContractId:(NSString *)contractId
                             success:(void (^)(id response))success
                             failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"userId\":\"%@\",\"contractId\":\"%@\"}", ROOTDATASOURCE.UserId,contractId];
    NSDictionary *params = @{@"operAtt":@"getFileListforSign",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}

/*
 *项目尽调附件查询
 */
+(void)getFileListforCheckWithProjectId:(NSString *)projectId
                                success:(void (^)(id response))success
                                failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"userId\":\"%@\",\"projectId\":\"%@\"}", ROOTDATASOURCE.UserId,projectId];
    NSDictionary *params = @{@"operAtt":@"getFileListforCheck",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}


/*
 *附件预览
 */
+(void)getDownLoadFileWithFlowContextId:(NSString *)path
                                success:(void (^)(id response))success
                                failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat:@"%@", path];
    NSDictionary *params = @{@"operAtt":@"downloadFile",@"path":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}
/*
 *附件保存
 */
+(void)getSaveFileWithFlowContextId:(NSString *)flowContextId
                             taskId:(NSString*)taskId
                            FileIds:(NSString*)fileIds
                            success:(void (^)(id response))success
                            failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"userId\":\"%@\",\"flowContextId\":\"%@\",\"taskId\":\"%@\",\"fileIds\":\"%@\"}", ROOTDATASOURCE.UserId,flowContextId,taskId,fileIds];
    NSDictionary *params = @{@"operAtt":@"saveContAttach",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}
/*
 *放款面签附件保存
 */
+(void)getsaveLoanSignRegistWithContractId:(NSString *)contractId
                                    FileId:(NSString *)fileId
                                      Type:(NSString *)type
                                   success:(void (^)(id response))success
                                   failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"fileId\":\"%@\",\"type\":\"%@\",\"userId\":\"%@\",\"contractId\":\"%@\"}",fileId,type,ROOTDATASOURCE.UserId,contractId];
    NSDictionary *params = @{@"operAtt":@"saveLoanSignRegist",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
    
}
/*
 *条件汇总附件列表
 */
+(void)getqueryConditionCollectWithId:(NSString *)Id
                              success:(void (^)(id response))success
                              failure:(void (^)(NSError *err))failure;
{
    NSString *param = [NSString stringWithFormat: @"{\"userId\":\"%@\",\"id\":\"%@\"}", ROOTDATASOURCE.UserId,Id];
    NSDictionary *params = @{@"operAtt":@"queryConditionCollect",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}
/*
 *代办条数
 */
+(void)getqueryDaibansuccess:(void (^)(id response))success
                     failure:(void (^)(NSError *err))failure;
{
    NSString *param = [NSString stringWithFormat: @"{\"userId\":\"%@\"}", ROOTDATASOURCE.UserId];
    NSDictionary *params = @{@"operAtt":@"queryDaiban",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}
/*
 *取消按钮
 */
+(void)abortWithFlowContextId:(NSString *)flowContextId
                      success:(void (^)(id response))success
                      failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"UserId\":\"%@\",\"FlowContextId\":\"%@\"}", ROOTDATASOURCE.UserId,flowContextId];
    NSDictionary *params = @{@"operAtt":@"abort",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}

/*
 *权限控制
 */
+(void)queryPersistsuccess:(void (^)(id response))success
                   failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"userId\":\"%@\"}", ROOTDATASOURCE.UserId];
    NSDictionary *params = @{@"operAtt":@"queryPersist",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}

/*
 *最终确认更还状态
 */
+(void)updateContStatusFileIds:(NSString *)fileIds
                   EffectState:(NSString *)effectState
                       success:(void (^)(id response))success
                       failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"fileIds\":\"%@\",\"effectState\":\"%@\"}", fileIds,effectState];
    NSDictionary *params = @{@"operAtt":@"updateContStatus",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}

/*
 * 附件删除
 */
+(void)fileDeleteWithFileId:(NSString *)fileId
                       Type:(NSString *)type
                    success:(void (^)(id response))success
                    failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"fileId\":\"%@\",\"type\":\"%@\",\"userId\":\"%@\"}", fileId,type,ROOTDATASOURCE.UserId];
    NSDictionary *params = @{@"operAtt":@"fileDelete",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}

/*
 * 附件确认
 */
+(void)fileConfirmWithFileId:(NSString *)fileId
                        Type:(NSString *)type
                  FileStatus:(NSString *)fileStatus
                     success:(void (^)(id response))success
                     failure:(void (^)(NSError *err))failure
{
    NSString *param = [NSString stringWithFormat: @"{\"fileId\":\"%@\",\"type\":\"%@\",\"fileStatus\":\"%@\",\"userId\":\"%@\"}", fileId,type,fileStatus,ROOTDATASOURCE.UserId];
    NSDictionary *params = @{@"operAtt":@"fileConfirm",@"param":param};
    [AFHttpTool requestWihtMethod:RequestMethodTypePost
                              url:UrlMain
                           params:params
                          success:success
                          failure:failure];
}




@end
